﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ninject;
using System.Web.Routing;
using TN_CMS.Domain.Concrete;
using TN_CMS.Domain.Abstract;
using Moq;
using TN_CMS.Domain.Entities;

namespace TN_CMS.Admin.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        private IKernel ninjectKernel;

        public NinjectControllerFactory()
        {
            ninjectKernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            return controllerType == null ? null : (IController)ninjectKernel.Get(controllerType);
        }

        private void AddBindings()
        {
            EFDbContext dbContext = new EFDbContext();
            // put bindings here
            ninjectKernel.Bind<ICommonRepository>().To<CommonRepository>();
            ninjectKernel.Bind<ISysAdminRepository>().To<EFSysAdminRepository>().WithConstructorArgument("context", dbContext);
            ninjectKernel.Bind<ISysRoleRepository>().To<EFSysRoleRepository>().WithConstructorArgument("context", dbContext);
            ninjectKernel.Bind<ISysFeatureRepository>().To<EFSysFeatureRepository>().WithConstructorArgument("context", dbContext);
            ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>().WithConstructorArgument("context", dbContext);
            ninjectKernel.Bind<IStaticContentRepository>().To<EFStaticContentRepository>().WithConstructorArgument("context", dbContext);
            ninjectKernel.Bind<IStaticContentGroupRepository>().To<EFStaticContentGroupRepository>().WithConstructorArgument("context", dbContext);
            ninjectKernel.Bind<INewsRepository>().To<EFNewsRepository>().WithConstructorArgument("context", dbContext);
            ninjectKernel.Bind<INewsGroupRepository>().To<EFNewsGroupRepository>().WithConstructorArgument("context", dbContext); 
        }
    }
}